{template 'common/header'}


<style>
    .calendar-time select {
        width: 83px !important;
        margin-bottom: 0;

    }
</style>

<ul class="nav nav-tabs">

    <li {if $op == 'add'} class="active"{/if}><a href="{php echo $this->createWebUrl('Spacemanage', array('op' => 'add'))}">添加空间</a></li>
    <li {if $op == 'display'} class="active"{/if}><a href="{php echo $this->createWebUrl('Spacemanage', array('op' => 'display'))}">空间管理</a></li>
    <li {if $op == 'editpro'} class="active"{/if}><a href="{php echo $this->createWebUrl('SpaceProManage', array('op' => 'display'))}">租赁时间编辑</a></li>

</ul>
<style>
    .label{line-height: 2}
    .danger{position: relative}
</style>
{if $op == 'editpro'}

<div class="panel panel-default">
    <div class="panel-body table-responsive">


        <form action="./" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">

            {loop $spacePros $spacePro}


            <div class="col-sm-3">

                <table class="table table-bordered table-hover table-responsive table-condensed" style="text-align: center">
                    <tr>
                        <td>时间</td>
                        <td>
                            {if $spacePro['status'] ==1}
                            <span class="label label-danger">{$spacePro['pro_name']}</span>
                            {else}
                            <span class="label label-default">{$spacePro['pro_name']}</span>
                            {/if}
                        </td>
                    </tr>
                    <tr>
                        <td>状态</td>
                        <td>
                            <label class="checkbox-inline">
                                <input type="checkbox" attr-pro_id = {$spacePro['id']} class="form-inline" {if $spacePro['status'] ==1} checked{/if} name="sel_time" value="{$spacePro['status']}">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td>价格</td>
                        <td>
                            <div class="input-group">
                                <div class="input-group-addon">￥</div>
                                <input type="text" class="form-control" id="exampleInputAmount" value="{$spacePro['price']}" placeholder="">
                                <div class="input-group-addon">.00</div>
                            </div>
                        </td>
                    </tr>
                </table>

            </div>


            {/loop}

        </form>


    </div>
</div>
{$pager}


<script>
    require(['bootstrap.switch'], function() {
        $(":checkbox[name='sel_time']").bootstrapSwitch(
            {
                onText:"启动",
                offText:"停止",
                size:'small',
                radioAllOff:'true',
                labelText:'点击改变',
                labelWidth:'',

            }
        );

        $(":checkbox[name='sel_time']").on('switchChange.bootstrapSwitch', function (e, state) {
            var _this = $(this);

            var status = this.checked ? 1 : 0;
            var pro_id = _this.attr('attr-pro_id');
            $.post("{php echo $this->createWeburl('SpaceProManage', array('op' => 'prostatus'));}", {status: status,pro_id:pro_id}, function (resp) {
                resp = $.parseJSON(resp);
                console.log(resp);
                if (resp.errCode == -1) {
                    util.message('操作失败, 请稍后重试.')
                } else {
                    util.message('操作成功',location.href, 'success');
                }
            });

        });
    })
</script>

<script type="text/javascript">

    function deleteAttr(_this) {
        var r=confirm("是否确认删除?");
        if(r == true)
        {
            //租赁空间id
            var space_id = $(_this).attr('attr-space_id');

            $.post("{php echo $this->createWeburl('Spacemanage', array('op' => 'delete'))}",
                {'space_id':space_id},
                function(data) {
                    var data = JSON.parse(data);
                    if(data.errCode == 0){
                        util.message(data.msg, 'refresh', 'success');
                    }else{
                        util.message(data.msg, 'refresh', 'error');
                    }
                });
        }
    }

    /**
     *
     * @param _this
     * @param _status 1 开启 2暂停
     */
    function updateStatus(_this,_status) {
        var _status = _status;
        var id = $(_this).attr('attr-id');
        console.log(id);

        $.post("{php echo $this->createWeburl('Spacemanage', array('op' => 'change_status'))}",
            {'id' : id,'status':_status},
            function(data) {
                var data = JSON.parse(data);
                if(data.errCode == 0){
                    util.message('更新成功', 'refresh', 'success');
//                util.message('删除成功', 'refresh', 'success');
                }else{
                    util.message('更新失败', '', 'error');
                }
            });
    }

    $(document).ready(function () {

        $(".changeValue").change(function () {
            var r=confirm("是否确认更改此属性名?");
            if(r == true){
                var _value = $(this).val();
                var id = $(this).attr('attr-id');
                $.post("{php echo $this->createWeburl('attrmanage', array('op' => 'edit'))}",
                    {'id' : id,'value':_value},
                    function(data) {
                        var data = JSON.parse(data);
                        if(data.errCode == 0){
                            util.message('更新成功', 'refresh', 'success');
                            //                util.message('删除成功', 'refresh', 'success');
                        }else{
                            util.message('更新失败', '', 'error');
                            $('#ajaxForm')[0].reset();
                        }
                    });
            }else{
                $('#ajaxForm')[0].reset();
            }
        })
    })

</script>


{elseif $op == 'add'}
<div class="panel panel-default"  id="input_body">
    <div class="panel-heading">
        添加空间
    </div>

    <div class="panel-body">


        <form action="./" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">

            <input type="hidden" name="c" value="site">
            <input type="hidden" name="a" value="entry">
            <input type="hidden" name="do" value="Spacemanage">
            <input type="hidden" name="m" value="orange_spacerental">
            <input type="hidden" name="op" value="add">
            <input name="token" type="hidden" value="{$_W['token']}" />

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">空间名:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <input required=""  type="text" attr-name="属性名" name="space_name" value="" class="form-control">

                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">空间地址:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <input required=""  type="text" attr-name="属性名" name="space_address" value="" class="form-control">

                </div>
            </div>

            <div class="form-group">

                <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">

                    <select class="form-control" name="type_id" id="">
                        <option required="" name="" value="">--请选择空间对应的分类--</option>
                        {loop $typeList $type}
                        <option name="" value="{$type['id']}">{$type['type_name']}</option>
                        {/loop}
                    </select>

                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">属性:<span style="color:red">*</span></label>

                <div class="col-sm-9 col-xs-12">
                    <label class="checkbox-inline">
                        <input type="checkbox" name="have_projection" value="1"> 投影仪
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="have_sound" value="1"> 音响
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="have_drinking" value="1"> 饮水机
                    </label>

                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>座位数:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <input required="" class="form-control" type="number" name="seats_number" min="1" max="10000" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">订购上限(0无限):<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <input required=""  type="number" attr-name="" name="space_address" value="0" class="form-control">

                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>空间照片:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    {php echo tpl_form_field_image('space_pic');}
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>空间简介:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    {php echo tpl_ueditor('space_intro');}
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">计费方式:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">

                    <label class="radio-inline">
                        <input required="" type="radio" name="pay_type"  value="1"> 按时间计费
                    </label>
                    <label class="radio-inline">
                        <input required="" type="radio" data-toggle="tooltip" data-placement="bottom" title="选择了按次数计费开放时间默认为全天" name="pay_type" value="2"> 按次数计费
                    </label>

                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">收费方式:<span style="color:red">*</span></label>

                <div class="col-sm-9 col-xs-12">

                    <label class="radio-inline">
                        <input required="" type="radio" name="charge_type" value="1"> 线上支付
                    </label>
                    <label class="radio-inline">
                        <input required="" type="radio" name="charge_type" value="1"> 线下支付
                    </label>
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">单价:<span style="color:red">*</span></label>

                <div class="col-sm-9 col-xs-12">
                    <div class="input-group">
                        <span class="input-group-addon">￥</span>
                        <input type="number" name="price" class="form-control" aria-label="">
                        <span class="input-group-addon">.00</span>
                    </div>

                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否免费开放:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">

                    <label class="radio-inline">
                        <input data-toggle="tooltip" data-placement="bottom" title="选择了免费开放则不走计费流程" type="radio" name="isfree"  value="1"> 是
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="isfree"  value="0"> 否
                    </label>
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">计时间隔:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">


                    <select class="form-control" id="charge_time" name="charge_time" id="">
                        <option  value="">--请选择计时间隔--</option>
                        <option  value="30">30分钟</option>
                        <option  value="15">15分钟</option>
                        <option  value="60">60分钟</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red"></span></label>
                <div class="col-sm-9 col-xs-9" id="timeCheck">

                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                <div class="col-sm-9 col-xs-12">
                    <input name="token" type="hidden" value="{$_W['token']}" />
                    <input name="submit" type="submit" class="btn btn-default" value="提交">

                </div>
            </div>
        </form>



    </div>
</div>

<script>

    // 将分钟数量转换为小时和分钟字符串
    function toHourMinute(minutes){
        var _h = Math.floor(minutes/60);
        var _m = minutes%60;
        if(_m<10){
            _m = _m + '0';
        }
        if(_h<10)
        {
            _h = '0' + _h;
        }
        return ( _h+ ":" + _m );
        // 也可以转换为json，以方便外部使用
        // return {hour:Math.floor(minutes/60),minute:(minutes%60)};
    }


    $("select#charge_time").change(function(){
        var _chargeTime = $(this).val();
        var _em = 1440/_chargeTime;
        var _html = '';
        for($i=0;$i<_em;$i++)
        {
            var t = toHourMinute($i*_chargeTime);
            var tnext = toHourMinute(($i+1)*_chargeTime);
            var str = t+'~'+tnext;
            var _html= _html + ' <label style="margin-left: 10px" class="checkbox-inline"><input type="checkbox" checked name="sel_time[]" value="'+str+'">'+
                '<span class="label label-danger">'+str+'</span></label>';
        }

        _html = '<div class="alert alert-success" role="alert"><strong>选择时间间隔成功! </strong> 请选择该租赁空间开放租赁的时间 </div>'+_html;
        $("#timeCheck").html(_html);


    });
</script>


<script>

    function add() {
        var obj =  $('form').serializeArray();

        console.log(obj);return;
        var _data = {};
        $(obj).each(function (i) {
            _data[this.name] = this.value;
        });
        $.post("{php echo $this->createWeburl('SpaceRentalProductManage', array('op' => 'add'))}",
            _data,
            function(data) {
                if(data.errCode == 0){
                    util.message(data.msg, 'refresh', 'success');
                }else{
                    util.message(data.msg,'','error');
                }
            },"JSON");
    }

</script>

{elseif $op == 'edit'}

<div class="alert alert-success" role="alert">

    <strong>温馨提示</strong>
    <p> 编辑功能可更改租赁空间的基本信息，不可更改租赁空间的 "租赁时间间隔", 如需更改租赁时间间隔请 <a class="btn btn-info" href="{php echo $this->createWebUrl('Spacemanage', array('op' => 'add'))}">添加新空间</a>，
        如需编辑当前租赁时间区间，请 <a class="btn btn-info" href="{php echo $this->createWebUrl('Spacemanage', array('op' => 'add'))}">编辑空间时间区间</a></p>

</div>

<div class="panel panel-default"  id="input_body">


    <div class="panel-heading">
        编辑空间
    </div>

    <div class="panel-body">


        <form action="./" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">

            <input type="hidden" name="c" value="site">
            <input type="hidden" name="a" value="entry">
            <input type="hidden" name="do" value="Spacemanage">
            <input type="hidden" name="m" value="orange_spacerental">
            <input type="hidden" name="op" value="edit">
            <input name="token" type="hidden" value="{$_W['token']}" />

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">空间名:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <input required=""  type="text" attr-name="属性名" name="space_name" value="{$spaceInfo['space_name']}" class="form-control">

                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">空间地址:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <input required=""  type="text" attr-name="属性名" name="space_address" value="{$spaceInfo['space_address']}" class="form-control">

                </div>
            </div>

            <div class="form-group">

                <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">


                    <select class="form-control" required="" name="type_id" id="">
                        <option required="" name="" value="">--请选择空间对应的分类--</option>
                        {loop $typeList $type}
                        <option   {if $spaceInfo['type_id']==$type['id']}  selected   {/if} name="" value="{$type['id']}">{$type['type_name']}</option>
                        {/loop}
                    </select>

                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">属性:<span style="color:red">*</span></label>

                <div class="col-sm-9 col-xs-12">
                    <label class="checkbox-inline">
                        <input {if $spaceInfo['have_projection']==1}  checked   {/if} type="checkbox" name="have_projection" value="1"> 投影仪
                    </label>
                    <label class="checkbox-inline">
                        <input {if $spaceInfo['have_sound']==1}  checked   {/if}  type="checkbox" name="have_sound" value="1"> 音响
                    </label>
                    <label class="checkbox-inline">
                        <input {if $spaceInfo['have_drinking']==1}  checked   {/if} type="checkbox" name="have_drinking" value="1"> 饮水机
                    </label>

                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>座位数:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <input required="" class="form-control" type="number" name="seats_number" value="{$spaceInfo['seats_number']}" min="1" max="10000" />
                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>空间照片:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    {php echo tpl_form_field_image('space_pic',$spaceInfo['space_pic']);}
                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>空间简介:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    {php echo tpl_ueditor('space_intro',$spaceInfo['space_intro']);}
                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">计费方式:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">

                    <label class="radio-inline">
                        <input {if $spaceInfo['pay_type']==1}  checked {/if} required="" type="radio" name="pay_type"  value="1"> 按时间计费
                    </label>
                    <label class="radio-inline">
                        <input {if $spaceInfo['pay_type']==2}  checked {/if} required="" type="radio" data-toggle="tooltip" data-placement="bottom" title="选择了按次数计费开放时间默认为全天" name="pay_type" value="2"> 按次数计费
                    </label>

                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">收费方式:<span style="color:red">*</span></label>

                <div class="col-sm-9 col-xs-12">

                    <label class="radio-inline">
                        <input {if $spaceInfo['pay_type']==1}  checked {/if} required="" type="radio" name="charge_type" value="1"> 线上支付
                    </label>
                    <label class="radio-inline">
                        <input {if $spaceInfo['pay_type']==2}  checked {/if} required="" type="radio" name="charge_type" value="2"> 线下支付
                    </label>
                </div>
            </div>


            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否免费开放:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">

                    <label class="radio-inline">
                        <input {if $spaceInfo['isfree']==1}  checked {/if} data-toggle="tooltip" data-placement="bottom" title="选择了免费开放则不走计费流程" type="radio" name="isfree"  value="1"> 是
                    </label>
                    <label class="radio-inline">
                        <input {if $spaceInfo['isfree']==0}  checked {/if} type="radio" name="isfree"  value="0"> 否
                    </label>
                </div>
            </div>

            <!--
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">计时间隔:<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">


                    <select class="form-control" id="charge_time" name="charge_time" id="">
                        <option  value="">--请选择计时间隔--</option>
                        <option  value="30">30分钟</option>
                        <option  value="15">15分钟</option>
                        <option  value="60">60分钟</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red"></span></label>
                <div class="col-sm-9 col-xs-9" id="timeCheck">

                </div>
            </div>
            !-->
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                <div class="col-sm-9 col-xs-12">
                    <input name="space_id" type="hidden" value="{$spaceInfo['id']}" />
                    <input name="submit" type="submit" class="btn btn-default" value="提交">
                </div>
            </div>
        </form>
    </div>
</div>

<script>

    // 将分钟数量转换为小时和分钟字符串
    function toHourMinute(minutes){
        var _h = Math.floor(minutes/60);
        var _m = minutes%60;
        if(_m<10){
            _m = _m + '0';
        }
        if(_h<10)
        {
            _h = '0' + _h;
        }
        return ( _h+ ":" + _m );
        // 也可以转换为json，以方便外部使用
        // return {hour:Math.floor(minutes/60),minute:(minutes%60)};
    }


    $("select#charge_time").change(function(){
        var _chargeTime = $(this).val();
        var _em = 1440/_chargeTime;
        var _html = '';
        for($i=0;$i<=_em;$i++)
        {
            var t = toHourMinute($i*_chargeTime);
            var tnext = toHourMinute(($i+1)*_chargeTime);
            var str = t+'~'+tnext;
            var _html= _html + ' <label style="margin-left: 10px" class="checkbox-inline"><input type="checkbox" checked name="sel_time[]" value="'+t+'">'+str+'</label>';
        }

        _html = '<div class="alert alert-success" role="alert"><strong>选择时间间隔成功! </strong> 请选择该租赁空间开放租赁的时间 </div>'+_html;
        $("#timeCheck").html(_html);


    });
</script>


<script>

    function add() {
        var obj =  $('form').serializeArray();

        console.log(obj);return;
        var _data = {};
        $(obj).each(function (i) {
            _data[this.name] = this.value;
        });
        $.post("{php echo $this->createWeburl('SpaceRentalProductManage', array('op' => 'add'))}",
            _data,
            function(data) {
                if(data.errCode == 0){
                    util.message(data.msg, 'refresh', 'success');
                }else{
                    util.message(data.msg,'','error');
                }
            },"JSON");
    }

</script>
{/if}